<template>
  <SuperTable ref="superTableRef" search :pager="false" border align="center" :columns="columns" :data-request="fetchData" :export-config="{}" header-title="操作统计" />
</template>

<script setup lang="ts">
import SuperTable from '@/framework/components/core/super-table/super-table.vue';
import { VxeGridPropTypes } from 'vxe-table';
import type { TableColumnItem } from './columns';
import { baseColumns } from './columns';
import { ref } from 'vue';
import { getInputOutData } from '@/api/common/common_data';

/**
 * table
 */
const superTableRef = ref<InstanceType<typeof SuperTable>>();
const columns: TableColumnItem[] = baseColumns;
const fetchData = async (ori: VxeGridPropTypes.ProxyAjaxQueryParams) => {
  let timeData = new Map();
  let data = superTableRef.value?.getFormModel();
  let params = {
    startTime: (data?.timeRange?.length && data?.timeRange[0]) ?? '',
    endTime: (data?.timeRange?.length && data?.timeRange[1]) ?? '',
  };
  const res = await getInputOutData(1, params);
  res.result.forEach((item) => {
    if (timeData.has(item.month)) {
      let it = timeData.get(item.month);
      it.tmpInCount = item.inCount;
      it.tmpOutCount = item.outCount;
    } else {
      timeData.set(item.month, {
        month: item.month,
        tmpInCount: item.inCount,
        tmpOutCount: item.outCount,
      });
    }
  });
  const subRes = await getInputOutData(2, params);
  subRes.result.forEach((item) => {
    if (timeData.has(item.month)) {
      let it = timeData.get(item.month);
      it.saveInCount = item.inCount;
      it.saveOutCount = item.outCount;
    } else {
      timeData.set(item.month, {
        month: item.month,
        saveInCount: item.inCount,
        saveOutCount: item.outCount,
      });
    }
  });
  let result = [...timeData.values()].sort((a: any, b: any) => {
    return a.month - b.month;
  });
  return {
    data: result,
    pageIndex: 1,
    pageSize: 10,
    total: 100,
  };
};
</script>

<style scoped lang="less"></style>
